/*
 * Copyright (C) 2022 KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef UNINSTALLER_H
#define UNINSTALLER_H

#include <QObject>
#include <QDebug>
#include <QSettings>
#include <QDBusConnection>
#include <QFile>
#include <dlfcn.h>
#include <QDBusInterface>
#include <QDBusPendingCall>
#include <QDBusPendingReply>

class Uninstaller : public QObject
{
    Q_OBJECT
public:
    explicit Uninstaller(QObject *parent = nullptr);
    void uninstallApp(const QString &desktopFile);

private:
    void doUninstallApp(const QString &desktopFile);
    bool uninstallAndroidApp(const QString &desktopCmd);
    QString getPkgNameByDesktop(const QString &desktopFile);
    void uninstallOrdinaryApp(const QString &desktopFile);
    void uninstallNextApp();

private:
    QString libPath = "";
    QList<QString> m_uninstallAppList;
    QString m_uninstallAppDesktopname;

private slots:
    void certificationResults(QDBusPendingCallWatcher *call);
    void ordinaryAppUninstallComplete(bool uninstallResults, QString uninstallMessage);

signals:
    void appUninstalled(const QString &desktopFile);
    void appUninstallFailed(const QString &desktopFile);

};

#endif // UNINSTALLER_H
